<!-- 会员配置 -->
<template>
  <div class="page-container">
    <s-table
      size="default"
      ref="table"
      rowKey="userId, title"
      :columns="columns"
      :rowSelection="null"
      :showPagination="false"
      :data="loadData"
    >
      <!-- 序号 -->
      <span slot="serial" slot-scope="text, record, index">
        {{ (pagination.current - 1) * pagination.pageSize + parseInt(index) + 1 }}
      </span>

      <!--  入会类型 -->
      <span slot="memberType" slot-scope="text">
        <template v-for="item in convertMemberType(text)">
          <div :key="item" class="disFlxAC">
            <DictTag :options="Dict.getLocal('memberTypeDict')" :value="Number(item)" isText />入会
            <a class="_ml-10" @click="handleFormConfig(item)">申请配置</a>
          </div>
        </template>
      </span>

      <!-- 是否启用 -->
      <!-- <span slot="enabled" slot-scope="text, record">
        <a-switch :checked="record.enabled === 1" @change="handleEnabledChange(record)" />
      </span> -->

      <div slot="action" slot-scope="text, record" class="disFlxAC flexWrap">
        <a-button type="primary" ghost size="small" class="_mr-5" @click="handleShowEditModal(record, 'edit')">
          编辑
        </a-button>
        <a-button type="primary" ghost size="small" class="_ml-10" @click="handleToPost(record)"> 职务管理 </a-button>
      </div>
    </s-table>

    <!-- 编辑会员架构 -->
    <EditModal ref="editModal" @success="refresh" />
  </div>
</template>

<script>
import { STable } from '@/components'
import EditModal from './modal/edit.vue'

import { OrganizationList, FormEnable } from '@/api/member/memberConfig'
import DictTag from '@/components/DictTag'

export default {
  components: {
    STable,
    EditModal,
    DictTag
  },
  data() {
    return {
      pagination: {
        current: 1,
        pageSize: 10,
      },
      // 活动表单
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' },
        },
        {
          title: '组织名称',
          dataIndex: 'name',
        },
        {
          title: '入会类型',
          dataIndex: 'memberType',
          scopedSlots: { customRender: 'memberType' },
        },
        {
          title: '会员数',
          dataIndex: 'memberNumber',
          ellipsis: true,
          scopedSlots: { customRender: 'printStyle' },
        },
        // {
        //   title: '启用开关',
        //   dataIndex: 'enabled',
        //   ellipsis: true,
        //   scopedSlots: { customRender: 'enabled' },
        // },
        {
          title: '操作',
          fixed: 'right',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      loadData: (parameter) => {
        return OrganizationList(Object.assign({ ...parameter }))
      },
      activityName: undefined,
    }
  },
  computed: {},
  watch: {},
  methods: {
    handleShowAddModal(row, type) {
      this.$refs.addModal.openModel({
        row,
        type,
      })
    },
    refresh() {
      this.$refs.table.refresh(false)
    },
    //下载二维码
    handleDownloadQrcode(row) {
      window.open(row.qrcode + `?attname=${row.signName}.jpg`, '_self')
    },
    //跳转配置表单
    handleFormConfig(type) {
      this.$router.push({
        path: '/member/formConfig',
        query: {
          type,
        },
      })
    },
    convertMemberType(memberType) {
      return memberType ? memberType.split(',') : []
    },
    handleShowEditModal(row) {
      this.$refs.editModal.openModel({
        ...row,
        memberTypeList: this.convertMemberType(row.memberType),
      })
    },
    handleToPost() {
      this.$router.push({
        path: '/member/memberPost',
      })
    },
    async handleEnabledChange(record) {
      let status = record.enabled === 0 ? 1 : 0
      await FormEnable(record.id, status)
      this.$message.success('操作成功')
      this.refresh()
    },
  },
  created() {
    this.activityName = this.$route.query.activityName
  },
  mounted() {},
}
</script>
<style scoped>
</style>